import { getUserInfoApi } from '@/api/user'
export default {
  namespaced: true,
  state: {
    userInfo: {}
  },
  mutations: {
    setUser (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  getters: {
    //  截取首字母  当成展示图片
    avatarImg (state) {
      console.log(state.userInfo, 1)
      /* 如果图片没有  就取用户名的首字母 并且大写 */
      // return state.userInfo.user_pic?state.userInfo.user_pic:state.userInfo.username.charAt(0).toUpperCase()
      return state.userInfo.username ? state.userInfo.username.charAt(0).toUpperCase() : ''
    }
  },
  actions: {
    async AgetUserInfo ({ commit }) {
      const res = await getUserInfoApi()
      console.log(res, 77)
      commit('setUser', res.data.data)
    }
  }
}
